package com.security.handler;

import com.security.po.MyUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;

/**
 * 自定义登录成功 业务逻辑
 */
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    private String url="";
    public MyAuthenticationSuccessHandler(String url) {
        this.url = url;
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        MyUser user = (MyUser) authentication.getPrincipal();
        //权限
        Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
        
        //密码
        String password = user.getPassword();


        httpServletResponse.sendRedirect(url);
    }
}
